package com.zhengdongzulin.zuke.app.main.activies

import androidx.lifecycle.rxLifeScope
import com.lxj.androidktx.livedata.StateLiveData
import com.zhengdongzulin.zuke.app.Api
import com.zhengdongzulin.zuke.app.data.activities.ActivitiesBean
import com.zhengdongzulin.zuke.app.data.activities.BannerBean
import com.zhengdongzulin.zuke.base.BaseViewModel
import rxhttp.wrapper.param.RxHttp
import rxhttp.wrapper.param.toResponse

class ActiviesVm : BaseViewModel() {

    var get_activity_list: StateLiveData<ActivitiesBean> = StateLiveData()

    fun get_activity_list(cityId: String?, pageNo: Int?) {
        rxLifeScope.launch(
            {
                var r = RxHttp.postJson(Api.GET_ACTIVITY_LIST)
                    .add("cityId", cityId)
                    .add("pageNo", pageNo)
                    .add("pageSize", 10)
                    .toResponse<ActivitiesBean>()
                    .await()
                get_activity_list.postValueAndSuccess(r)
            }, {
                assignment(it, get_activity_list)
            }
        )
    }

    var get_banner_pic_list: StateLiveData<BannerBean> = StateLiveData()

    /**
     * picStatus	否	string	状态（0，禁用；1，启用）
     */
    fun get_banner_pic_list(cityId: String?, picStatus: String = "1") {
        rxLifeScope.launch(
            {
                var r = RxHttp.postJson(Api.GET_BANNER_PIC_LIST_ACTIVITY)
                    .add("cityId", cityId)
                    .add("wechatId", mShareViewModel!!.apartmentTypeId.value!!)
                    .add("status", picStatus)
                    .toResponse<BannerBean>()
                    .await()
                get_banner_pic_list.postValueAndSuccess(r)
            }, {
                assignment(it, get_banner_pic_list)
            }
        )
    }

}